Beacon Chain Spec: State transition
1. State caching, which happens at the start of every slot.
2. The per-epoch transitions, which happens at the start of the first slot of every epoch.
3. The per-slot transitions, which happens at every slot.
4. The per-block transitions, which happens at every block.
code: transition.go
// transition.go
// happens at the start of every Slot
for i := state.Slot; i < block.Slot; i++ {
AdvanceSlot(state)
}
// happens at every block
if err := ApplyBlock(state, block); err != nil {
return nil, err
}
// "happens at the end of the last Slot of every epoch "
if (state.Slot+1)%beacon.SLOTS_PER_EPOCH == 0 {
EpochTransition(state)
}
//block_transition.go
var blockProcessors = []BlockProcessor{
block_processing.ProcessBlockHeader,
block_processing.ProcessBlockRandao,
block_processing.ProcessBlockEth1,
block_processing.ProcessBlockProposerSlashings,
block_processing.ProcessBlockAttesterSlashings,
block_processing.ProcessBlockAttestations,
block_processing.ProcessBlockDeposits,
block_processing.ProcessBlockVoluntaryExits,
block_processing.ProcessBlockTransfers,
}
// epoch_transition.go
var epochProcessors = []EpochProcessor{
epoch_processing.ProcessEpochEth1,
epoch_processing.ProcessEpochJustification,
epoch_processing.ProcessEpochCrosslinks,
epoch_processing.ProcessEpochRewardsAndPenalties,
epoch_processing.ProcessEpochValidatorRegistry,
epoch_processing.ProcessEpochSlashings,
epoch_processing.ProcessEpochExitQueue,
epoch_processing.ProcessEpochFinish,
}
references